package _11synchronized保证原子性;

public class Demo {
    static int x = 0;
    static Object o =new Object();
    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100000; i++) {
                    synchronized (o){
                        x++;
                    }

                }

                System.out.println(x);
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100000; i++) {
                    synchronized (o){
                        x++;
                    }
                }
                System.out.println(x);
            }
        }).start();

    }

}